package com.sky.mapper;/**
 * @ProjectName: sky-take-out
 * @Package: com.sky.mapper
 * @ClassName: UserMapper
 * @Author: 王加其
 * @Date: 2023/4/21 19:37
 * @Version: 1.0
 */

import com.sky.annotation.AutoFill;
import com.sky.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

import static com.sky.enumeration.OperationType.INSERT;

/**
 *@author:王加其
 *@date:2023/4/21 19:37
 *@modified By:
 **/
@Mapper
public interface UserMapper {
    /**
     * 根据openId查询用户
     * @param openId
     * @return
     */
    @Select("select * from user where openid = #{openId}")
    User queryByOpenid(String openId);

    /**
     * 保存c端用户
     * @param user
     */
    @AutoFill(INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into user (openid, name, phone, sex, id_number, avatar, create_time) values " +
            "(#{openid},#{name},#{phone},#{sex},#{idNumber},#{avatar},#{createTime})")
    void save(User user);

    @Select("select * from user where id = #{userId}")
    User getById(Long userId);


    /**
     * 每天新增用户数
     * @param params
     * @return
     */
    Integer countUserByParams(Map params);
    List<Map> groupCountUserByParams(Map params);

    /**
     * 根据动态条件统计用户数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

}
